
package com.jedi;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import com.tss.util.DbConn;
import com.tss.util.DbRs;

/**
 * 
 * @author king
 *
 */

public abstract class BaseObj {
	private List err = null;
	private int numTop = 8;
	private int total = 0;
	 private int sumnormaltime=0;
	 private int sumworktime=0;
	 private int sumacttime=0;
	 private int sumtotdays=0;
	 private double sumtripfee=0.00;
	 
	
	public int getSumacttime() {
		return sumacttime;
	}
	public void setSumacttime(int sumacttime) {
		this.sumacttime = sumacttime;
	}
	public double getSumtripfee() {
		return sumtripfee;
	}
	public void setSumtripfee(double sumdtripfee) {
		this.sumtripfee = sumdtripfee;
	}
	public int getSumnormaltime() {
		return sumnormaltime;
	}
	public void setSumnormaltime(int sumnormaltime) {
		this.sumnormaltime = sumnormaltime;
	}
	public int getSumtotdays() {
		return sumtotdays;
	}
	public void setSumtotdays(int sumtotdays) {
		this.sumtotdays = sumtotdays;
	}
	public int getSumworktime() {
		return sumworktime;
	}
	public void setSumworktime(int sumworktime) {
		this.sumworktime = sumworktime;
	}
	public int getTotal() {return total;}
	protected void setTotal(int num) {
		this.total = num;
	}
	
	protected int getTopNum() {return numTop;}
	public void setTopNum(int num) {this.numTop = num;}
	public boolean hasErr() {
		if (err == null || err.size() == 0) return false;
		return true;
	}
	
	protected void setErr(String strErr) {
		if (err == null) err = new ArrayList();
		err.add(strErr);
	}
	
	protected void setErr(List subErr) {
		if (subErr == null || subErr.size() == 0) return;
		if (err == null) err = new ArrayList();
		for(int i=0;i<subErr.size();i++) {
			err.add(subErr.get(i));
		}
	}
	
	protected void clearErr() {
		if (err != null) {
			err.clear();
		}
	}
	
	public List getErr() {
		return err;
	}
	
	public String getErrStr() {
		if (err == null || err.size() == 0) return "";
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<err.size();i++) {
			if (i > 0) sb.append("\n");
			sb.append((String)err.get(i));
		}
		return sb.toString();		
	}
	
	public String getErrHtml() {
		if (err == null || err.size() == 0) return "&nbsp;";
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<err.size();i++) {
			if (i > 0) sb.append("<br>");
			sb.append((String)err.get(i));
		}
		return sb.toString();		
	}
	
	
	protected String get(DbRs rs,int row,String field) {
		try {
			return rs.get(row,field);
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		return "";
	}
	
	protected String get(DbRs rs,int row,int field) {
		try {
			return rs.get(row,field);
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		return "";
	}
	
	protected int getInt(DbRs rs,int row,String field) {
		try {
			return rs.getInt(row,field);
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		return 0;
	}
	protected boolean getBoolean(DbRs rs,int row, String field) {
		try {
			return rs.getBoolean(row, field);
		}
		catch(Exception ex) { 
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		return false;
	}
	protected int getInt(DbRs rs,int row,int field) {
		try {
			return rs.getInt(row,field);
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		return 0;
	}
	protected Date getDate(DbRs rs,int row,String field) {
		try {
			return rs.getDate(row,field);
			
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		return null;
	}
	protected double getDouble(DbRs rs,int row, String field) {
		try {
			return rs.getDoulbe(row,field);
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		return 0;
	}
	protected long getLong(DbRs rs,int row,String field) {
		try {
			return rs.getLong(row,field);
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		return 0;
	}
	
	public void updateSQL(String sql) {
		clearErr();
		DbConn conn = new DbConn();
		try {
			conn.prepare(sql);
			conn.executeUpdate();
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		finally {
			conn.close();
		}
	}
	
	public DbRs getList(String sql,int pageNo, int pageSize) {
		clearErr();
		DbConn conn = new DbConn();
		try {
			conn.prepare(sql);
			return conn.executeQuery(pageNo,pageSize);
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
	}
	
	public DbRs getList(String sql) {
		clearErr();
		DbConn conn = new DbConn();
		try {
			conn.prepare(sql);
			return conn.executeQuery();
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
	}
	
	protected long getLong(DbRs rs,int row,int field) {
		try {
			return rs.getLong(row,field);
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
		}
		return 0;
	}
}
